callback subroutine
'
'
' ***** Callback ***** message = Callback : r1 = original message
'
SUB Callback
  message = r1
  callback = message
  IF (message <= upperMessage) THEN GOSUB @sub[message]
END SUB

The Callback subroutines in grid functions generated by GuiDesigner are not executed.   That's because GuiDesigner puts the following statements near the bottom of the grid function:

  func[#Callback] = &XuiCallback ()
' sub[#Callback] = SUBADDRESS (Callback)

The first statement makes the grid function pass Callback messages back to the function that set itself as its callback function, while the second statement is commented to disable the Callback subroutine.

Thus GuiDesigner generated grid functions create visual only grids.  Any functionality or special purpose is provided by the callback function set for each grid.   As a result, every grid can have unique functionality, since each can have its own callback function.

To create grids with special purpose functionality, a grid function must process the callback messages it receives from its kid grids.  Comment out the func[#Callback] line and enable sub[#Callback].  The Callback subroutine will now execute when the grid function receives Callback messages.

The lines in the Callback subroutine transfer the original message from r1 to message , set variable callback = message, then call the subroutine that processes the original message.  The transfer from r1 to message is necessary because XuiCallback() puts the original message in r1 and a Callback message in message.

Almost all callback messages carry a Selection message in r1.  So in most cases, all you have to do to add special purpose functionality to a grid function is add a SELECT CASE block to the Selection subroutine, with one CASE entry for each kid constant.   In fact, if you've already added the special purpose functionality in a callback function, you can simply copy its Selection subroutine into the grid function, plus any other code that supports it.

Whenever a function needs to know whether it received a particular message in a callback or not, it can test its local callback variable. callback = 0 means the message is not a callback message, otherwise callback contains the callback message number.